import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;

import com.example.administrator.myapplication.R;

/**
 * Created by Administrator on 2020/11/5.
 */
//通过NEW class 的方式创建一个android页面的方式创建一个android页面
public class TwoActivity extends AppCompatActivity{

    private AlertDialog alertDialog;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_two);
        initView();
        initData();
        initEvent();
    }
    private void initView() {
        AlertDialog.Builder dialog = new AlertDialog.Builder(this)
                .setTitle("普通对话框")
                .setIcon(R.mipmap.ic_launcher)
                .setMessage("是否确定退出应用")
                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int i) {
                        alertDialog.dismiss();
                        Toast.makeText(TwoActivity.this, "你点击了确定按钮", Toast.LENGTH_LONG).show();
                    }

                })
                .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int i) {
                        alertDialog.dismiss();
                        Toast.makeText(TwoActivity.this,"你点击了取消按钮",Toast.LENGTH_LONG).show();
                    }
                });
        alertDialog = dialog.create();
          alertDialog.show();

    }
    private void initData(){

    }
    private  void initEvent(){

    }
}
